package com.bytecodezz.app.sketch.main.model

import android.os.CountDownTimer
import androidx.lifecycle.MutableLiveData
import com.bytecodezz.app.sketch.common.base.BaseUIViewModel

/**
 * @author: bytecodezz
 * @version: 1.0
 * @time: 2021/7/6 18:30
 * @package: com.bytecodezz.app.ui.launcher.model
 *
 * @description:
 *
 */
class WelcomeFragmentViewModel : BaseUIViewModel() {

    var jumpUrl: String? = null
    val screenChangeEvent = MutableLiveData<Boolean>()
    val finishPagerEvent = MutableLiveData<Boolean>()
    val countDownContentEvent = MutableLiveData<String>()

    private var startTimer: CountDownTimer? = null


    fun screenStatusChange(isFullScreen: Boolean) {
        screenChangeEvent.value = isFullScreen
    }

    fun initLoadData() {
    }

    fun startTimer() {
        startTimer = object : CountDownTimer(3100, 101) {
            override fun onTick(millisUntilFinished: Long) {
                countDownContentEvent.value = "点击跳过 ${(millisUntilFinished / 1000) + 1}"
            }

            override fun onFinish() {
                finishPager()
            }
        }
        startTimer?.start()
    }

    fun finishPager() {
        finishPagerEvent.value = finishPagerEvent.value ?: true
        startTimer?.let {
            it.cancel()
            startTimer = null
        }
    }
}